package gwt.trading.client;

import gwt.trading.client.geometry.Padding;

/**
 * A mediator that takes care of translation and transformation.
 * 
 * @author Iulian Costan (iulian.costan@gmail.com)
 */
public class DrawingManager {

	private Transformer transformer;
	private Translator translator;

	/**
	 * @param transformer
	 *            the transformer instance
	 * @param translator
	 *            the translator instance
	 */
	public DrawingManager(Transformer transformer, Translator translator) {
		this.transformer = transformer;
		this.translator = translator;
	}

	/**
	 * @param barIndex
	 *            the index of vertical bar
	 * @return absolute position (in pixels) on X axis
	 */
	public int getXPosition(int barIndex) {
		int xRelative = transformer.transformToXCoordinate(barIndex);
		int xAbsolute = translator.translateXCoordinate(xRelative);
		return xAbsolute;
	}

	/**
	 * @param yValue
	 *            the value that has to be transformed in graph coordinate
	 * @return the absolute position (in pixels) on Y asis
	 */
	public int getYPosition(float yValue) {
		int yRelative = transformer.transformToYCoordinate(yValue);
		int yAbsolute = translator.translateYCoordinate(yRelative);
		return yAbsolute;
	}

	// public int translateXPosition(int xCoordinate) {
	// return translator.translateXCoordinate(xCoordinate);
	// }
	//
	// public int translateYPosition(int yCoordinate) {
	// return translator.translateYCoordinate(yCoordinate);
	// }

	public int getMaxYPosition() {
		int maxYRelative = transformer.getMaxYPosition();
		return translator.translateYCoordinate(maxYRelative);
	}

	/**
	 * @return the position of max value on X scale
	 */
	public int getMaxXPosition() {
		int maxXRelative = transformer.getMaxXPosition();
		return translator.translateYCoordinate(maxXRelative);
	}

	public DrawingManager shrink(int width, int height, int xOffset, int yOffset, Padding padding) {
		Translator newTranslator = translator.move(xOffset, yOffset);
		Transformer newTransormer = null;
		return new DrawingManager(newTransormer, newTranslator);
	}
}
